<?php
#####################################
# * @Author: lehieu008              #
# * @Email: lehieu008@gmail.com     #
# * @Copyright: 2008 - 2010         #
#####################################
if(!defined('BASEPATH'))exit('No direct script access allowed');
class Global_model extends Model
{
    function __construct()
    {
        parent::Model();
    }
    
    function get($sql, $cache = false)
    {
        if($cache == true)
        {
            $this->db->cache_on();
        }
        else
        {
            $this->db->cache_off();
        }
        $query = $this->db->query($sql);
        $result = $query->row();
        $query->free_result();
        return $result;
    }
    
    function fetch($sql, $cache = false)
    {
        if($cache == true)
        {
            $this->db->cache_on();
        }
        else
        {
            $this->db->cache_off();
        }
        $query = $this->db->query($sql);
        $result = $query->result();
        $query->free_result();
        return $result;
    }
    
    function insert($table = '', $data = array())
    {
        return $this->db->insert($table, $data);
    }
    
    function update($table = '', $data = array(), $where = '')
    {
        if(is_array($data))
        {
            if($where && $where != '')
            {
                $this->db->where($where);
            }
            return $this->db->update($table, $data);
        }
        return $this->db->query("UPDATE $table SET $data WHERE $where");
    }
    
    function delete($table = '', $where = '')
    {
        if($where && $where != '')
        {
            $this->db->where($where);
        }
        return $this->db->delete($table);
    }
}